<?php

use Illuminate\Database\Seeder;
use App\User;

class UserTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $u1=new User();
        $u1->name='admin';
        $u1->password=bcrypt('123456');
        $u1->type=1;
        $u1->save();
        
        $this->newAdviser('doctor','123456',2);

        $this->newCommonUser('ivan','123456');
    }

    private function  newCommonUser($username,$pwd){
        $u1=new User();
        $u1->name=$username;
        $u1->password=bcrypt($pwd);
        $u1->type=0;
        $u1->save();
        $adviceC=new \App\Http\Controllers\Advice\AdviceController();
        $adviceC->distributeAdviser($u1->name);
    }

    private function newAdviser($username,$pwd,$type){
        $u1=new User();
        $u1->name=$username;
        $u1->password=bcrypt($pwd);
        $u1->type=$type;
        $u1->save();
        \App\Adviser::create([
            'name'=>$username,
            'type'=>$type,
            'countUsers'=>0,
        ]);
    }
}
